<template>
  <div>
    <ZgDialog
      v-model="visible"
      title="新增视图"
      top="10%"
      width="30%"
      @ok="save">
      <a-form :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }">
        <a-form-item label="视图名称" required>
          <ZgInput v-model="obj.name"></ZgInput>
        </a-form-item>
        <a-form-item label="视图类型" required>
          <ZgDictionary v-model="obj.type" code="viewType"></ZgDictionary>
        </a-form-item>
      </a-form>
    </ZgDialog>
  </div>
</template>
<script>
export default {
  props: {
    formId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      visible: false,
      obj: {
        name: '',
        type: 'add'
      }
    }
  },
  methods: {
    open () {
      this.visible = true
    },
    save () {
      if (this.formId.length === 0) {
        this.$warning({ title: '请选择表单' })
        return
      }
      if (this.obj.name.length === 0) {
        this.$warning({ title: '请输入视图名称' })
        return
      }
      if (this.obj.type.length === 0) {
        this.$warning({ title: '请选择视图类型' })
        return
      }
      this.$http.post('/zg-autoform/view/add',
        Object.assign({
          formId: this.formId
        }, this.obj), () => {
          this.visible = false
          this.$emit('ok')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
